package com.ctshk.rpc.custom.mapper;


import com.ctshk.rpc.custom.base.CustomBaseMapper;
import com.ctshk.rpc.custom.dto.trip.TripScheduleVisaDTO;
import com.ctshk.rpc.custom.dto.trip.VisaDTO;
import com.ctshk.rpc.custom.dto.trip.VisaDetailDTO;
import com.ctshk.rpc.custom.entity.CustomizedTripScheduleVisa;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 团期签证 Mapper 接口
 * </p>
 *
 * @author 谢诗宏
 * @since 2021-01-20
 */
public interface CustomizedTripScheduleVisaMapper extends CustomBaseMapper<CustomizedTripScheduleVisa> {

    /**
     * 获取团期签证列表
     * @param scheduleId
     * @return
     */
    @Select("SELECT a.id,a.visa_id,a.`name`,b.country_name,b.flag_url,b.visa_type,b.stay_time,b.visa_vaild_date,b.send_visa_type,b.vaild_times,b.required_information,b.files_json,b.handle_instruction FROM\n" +
            "t_customized_trip_schedule_visa a LEFT JOIN t_visa b ON a.visa_id = b.id\n" +
            "WHERE a.schedule_id = #{schedule_id} and a.is_deleted = 0 ORDER BY a.gmt_create ASC")
    List<TripScheduleVisaDTO> queryListBySchedule(@Param("schedule_id") Long scheduleId);

    /**
     * 根据团期获取签证详情
     * @param scheduleId
     * @return
     */
    @Select("SELECT b.`name`,b.files_json,b.create_id FROM \n" +
            "t_customized_trip_schedule_visa a LEFT JOIN t_visa b ON a.visa_id = b.id\n" +
            "WHERE a.schedule_id = #{schedule_id} AND a.is_deleted = 0 LIMIT 1")
    VisaDTO queryFilesJsonBySchedule(@Param("schedule_id")Long scheduleId);

    /**
     * 查询签证详细列表
     * @param scheduleId
     * @return
     */
    @Select("SELECT a.visa_id,a.`name`,c.cost_amount,c.currency_id,c.currency,c.planned_exchange_rate,d.adjust_type,d.amount,d.percent \n" +
            "FROM t_customized_trip_schedule_visa a \n" +
            "LEFT JOIN t_visa b ON a.visa_id = b.id \n" +
            "LEFT JOIN t_visa_type c ON a.visa_id = c.visa_id\n" +
            "LEFT JOIN t_visa_product d ON b.id = d.visa_id\n" +
            "WHERE a.schedule_id = #{schedule_id} AND a.is_deleted = 0 AND b.is_deleted = 0")
    List<VisaDetailDTO> queryBySchedule(@Param("schedule_id")Long scheduleId);
}
